from parsers import *
from parserorkut import *

def get_friends(orkut_session, target):
    ret = []
    friends = ParserOrkut('friends', target.friends)
    friends.parse()
    ret += friends.get_friends()
    while friends.has_next_link():
        html = orkut_session.do_request(friends.get_next_link(), "orkut")
        friends = ParserOrkut('friends', html)
        friends.parse()
        ret += friends.get_friends()
    return ret

def get_cross_scraps(orkut_session, target, friend):
    ret = []
    if friend.scrapbook == "" or friend.scrapbook == None:
        return ret
    scrapbook = ParserOrkut('scrapbook', friend.scrapbook)
    scrapbook.parse()
    list = scrapbook.get_scraps()
    for i in list:
        if target.uid == i[0]:
            ret.append(i)
    while scrapbook.has_next_link():
        html = orkut_session.do_request(scrapbook.get_next_link(), "orkut")
        scrapbook = ParserOrkut('scrapbook', html)
        scrapbook.parse()
        list = scrapbook.get_scraps()
        for i in list:
            if target.uid == i[0]:
                ret.append(i)
    return ret

def get_cross_testimonials(orkut_session, target, friend):
    ret = []
    testimonials = ParserOrkut('profile', friend.profile)
    testimonials.parse()
    list = testimonials.get_testimonials()
    for i in list:
        if target.uid == i[0]:
            ret.append(i)
    while testimonials.has_next_link():
        html = orkut_session.do_request(testimonials.get_next_link(), "orkut")
        testimonials = ParserOrkut('profile', html)
        testimonials.parse()
        list = testimonials.get_testimonials()
        for i in list:
            if target.uid == i[0]:
                ret.append(i)
    return ret

def get_communities(orkut_session, target):
    ret = []
    communities = ParserOrkut('communities', target.communities)
    communities.parse()
    ret += communities.get_communities()
    while communities.has_next_link():
        html = orkut_session.do_request(communities.get_next_link(), "orkut")
        communities = ParserOrkut('communities', html)
        communities.parse()
        ret += communities.get_communities()
    return ret

def get_testimonials(orkut_session, target):
    ret = []

    testimonials = ParserOrkut('profile', target.profile)
    testimonials.parse()
    ret += testimonials.get_testimonials()

    while testimonials.has_next_link():
        html = orkut_session.do_request(testimonials.get_next_link(), "orkut")
        testimonials = ParserOrkut('profile', html)
        testimonials.parse()
        ret += testimonials.get_testimonials()

    return ret

def get_scraps(orkut_session, target):
    ret = []
    if target.scrapbook == "" or target.scrapbook == None:
        return ret
    scrapbook = ParserOrkut('scrapbook', target.scrapbook)
    scrapbook.parse()
    ret += scrapbook.get_scraps()
    while scrapbook.has_next_link():
        html = orkut_session.do_request(scrapbook.get_next_link(), "orkut")
        scrapbook = ParserOrkut('scrapbook', html)
        scrapbook.parse()
        ret += scrapbook.get_scraps()
    return ret

#EOF
